package GUI;

import java.sql.SQLException;
import java.util.ArrayList;

import javax.swing.*;
import javax.swing.GroupLayout.*;

import Config.GeneralsConfig;
import FileStatus.LocalFile;
import GUI.List.NewList;
import GUI.MenuBar.NewMenuBar;
import GUI.TabPanel.TabPanel;
import Net.Nets;

public class MainFrame extends JFrame {
	

	private static final long serialVersionUID = 1L;
	private NewList List;
	private TabPanel TabPanels;
	private NewMenuBar Bar;
	
	public void addHost(ArrayList<String> hosts) {
		this.List.addHost(hosts);
		LocalFile.initMac(hosts);
	}
	
	private void initMainFrame(String title) {
		List = new NewList();
		TabPanels = new TabPanel();
		Bar = new NewMenuBar();
		
		this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		this.setTitle(title);
		this.setJMenuBar(Bar);
		this.List.setPanel(TabPanels);
		
		GroupLayout layout = new GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        
        layout.setHorizontalGroup(
            layout.createParallelGroup(Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(List, GroupLayout.PREFERRED_SIZE, 180, GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(TabPanels, GroupLayout.DEFAULT_SIZE, 600, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(Alignment.LEADING)
            .addComponent(List, GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE)
            .addComponent(TabPanels, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        
        this.pack();
	}
	
	public MainFrame(String title) {
		this.initMainFrame(title);
	}
	
	public static void main(String[] arge) throws SQLException {
	    
	    /** 测试 
	    GeneralsConfig.stringAcToken = "rO0ABXNyABliYWlkdXBjcy5hdXRoLkFjY2Vzc1Rva2VuAAAAAAAAAAECAAZM"
	            + "AAZhcGlLZXl0ABJMamF2YS9sYW5nL1N0cmluZztMAAdhcHBOYW1lcQB+AAFMAApleHBpcmVUaW1lcQB+A"
	            + "AFMAAxyZWZyZXNoVG9rZW5xAH4AAUwACXNlY3JldEtleXEAfgABTAAFdG9rZW5xAH4AAXhwdAAYZkJFUU"
	            + "lHcExWeXlnTDBzeW1TcVN6SE5JdAAMUENTX1BhbmRvcmEydAANMTQxOTk0NTc3NjE3NHQASzIyLmZjYzY"
	            + "4NWU1MmRjMzZjZjI2YTgwNTdkYTYyNGZjMzRmLjMxNTM2MDAwMC4xNzMyNzEzNzc1LjI1Njc1MzkzNzAt"
	            + "NDQyNTk1MXQAIDA5RE45UDB2ZXZ1dTUzRFRoOUdYcUNjOWxFZ1VxOFVIdABJMjEuYzY1MzE4YjUxNzlkM"
	            + "TVmMGYwMDY1YTk5OGQzOTY3OGIuMjU5MjAwMC4xNDE5OTQ1Nzc1LjI1Njc1MzkzNzAtNDQyNTk1MQ==";*/
	    
		MainFrame Goin = new MainFrame("Pandora2");
		Goin.setVisible(false);
		ArrayList<String> hosts = Nets.getList();
		Goin.addHost(hosts);
		Nets.runThread(hosts);
		Goin.setVisible(true);
	}

}
